package com.ruoyi.web.controller.gcgl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.commons.collections.map.HashedMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DecimalCalculateUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.uuid.ReturnUUID;
import com.ruoyi.gcgl.domain.GcBszbzfd;
import com.ruoyi.gcgl.domain.GcClbxd;
import com.ruoyi.gcgl.domain.GcCustomer;
import com.ruoyi.gcgl.domain.GcFyhx;
import com.ruoyi.gcgl.domain.GcProject;
import com.ruoyi.gcgl.domain.SjProcessConfig;
import com.ruoyi.gcgl.domain.SjProjectPeople;
import com.ruoyi.gcgl.domain.YyBidding;
import com.ruoyi.gcgl.domain.YyContract;
import com.ruoyi.gcgl.domain.YyFk;
import com.ruoyi.gcgl.domain.YyProject;
import com.ruoyi.gcgl.domain.YyProjectMilestone;
import com.ruoyi.gcgl.domain.YyProjectQrsk;
import com.ruoyi.gcgl.domain.YyProjectReust;
import com.ruoyi.gcgl.domain.YyProjectSqkp;
import com.ruoyi.gcgl.service.IGcBszbzfdService;
import com.ruoyi.gcgl.service.IGcClbxdService;
import com.ruoyi.gcgl.service.IGcCustomerService;
import com.ruoyi.gcgl.service.IGcFyhxService;
import com.ruoyi.gcgl.service.IGcSendTipService;
import com.ruoyi.gcgl.service.IGcSupplyService;
import com.ruoyi.gcgl.service.ISjProcessConfigService;
import com.ruoyi.gcgl.service.ISjProjectPeopleService;
import com.ruoyi.gcgl.service.IYyBiddingService;
import com.ruoyi.gcgl.service.IYyContractService;
import com.ruoyi.gcgl.service.IYyFkService;
import com.ruoyi.gcgl.service.IYyFkfpService;
import com.ruoyi.gcgl.service.IYyFkitemService;
import com.ruoyi.gcgl.service.IYyProjectMilestoneService;
import com.ruoyi.gcgl.service.IYyProjectQrskService;
import com.ruoyi.gcgl.service.IYyProjectReustService;
import com.ruoyi.gcgl.service.IYyProjectService;
import com.ruoyi.gcgl.service.IYyProjectSqkpService;
import com.ruoyi.gcgl.service.IYyProjectSqkpfpService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysDictDataService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;

/**
 * 项目立项Controller
 * 
 * @author ruoyi
 * @date 2022-11-17
 */
@Controller
@RequestMapping("/yy/project")
public class YyProjectController extends BaseController{
    private String prefix = "yy/project";

    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private IYyProjectService gcProjectService;
    @Autowired
    private IGcCustomerService gcCustomerService;
    @Autowired
    private IYyFkService gcFkService;
    @Autowired
    private IYyFkitemService gcFkitemService;
    @Autowired
    private IYyFkfpService gcFkfpService;
    @Autowired
    private IGcSupplyService gcSupplyService;
    @Autowired
    private IYyProjectSqkpService gcProjectSqkpService;
    @Autowired
    private IGcSendTipService gcSendTipService;
    @Autowired
    private IYyProjectSqkpfpService gcProjectSqkpfpService;
    @Autowired
    private ISysDictDataService sysDictDataService;
    @Autowired
    private IYyProjectMilestoneService sjProjectMilestoneService;
    @Autowired
    private IYyProjectQrskService gcProjectQrskService;
    @Autowired
    private IYyBiddingService sjBiddingService;
    @Autowired
    private IGcBszbzfdService gcBszbzfdService;//保证金
    @Autowired
    private IGcClbxdService gcClbxdService;//差旅
    @Autowired
    private IGcFyhxService gcFyhxService;//费用核销
    @Autowired
    private IYyContractService sjContractService;
    @Autowired
    private ISysRoleService roleService;
    @Resource
    private RuntimeService runtimeService;
    @Resource
    private TaskService taskService;
    @Autowired
    private ISjProcessConfigService sjProcessConfigService;
    @Autowired
    private ISysDeptService deptService;
    @Autowired
    private ISjProjectPeopleService sjProjectPeopleService;
    @Autowired
    private IYyProjectReustService sjProjectReustService;
    
    final String processCode = "sjxiangmulixiang";
    
    @GetMapping("/home")
    public String home(ModelMap mmap){
        return "yy/project/projectDetail";
    }
    
    @GetMapping("/editHome/{id}")
    public String editHome(ModelMap mmap,@PathVariable("id") Long id){
    	YyProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        
        YyContract sjContract = new YyContract();
        sjContract.setDeleteFlag(1);
        sjContract.setGcProjectId(id);
        List<YyContract> sjconlis = sjContractService.selectSjContractList(sjContract);
        if(sjconlis!=null && sjconlis.size()>0){
        	mmap.put("gznr", sjconlis.get(0).getDescs());
        }
        
        //---里程碑
        int milestone = 0;
        YyProjectMilestone sjProjectMilestone = new YyProjectMilestone();
        sjProjectMilestone.setDeleteFlag(1);
        sjProjectMilestone.setGcProjectid(id);
        sjProjectMilestone.setpId(0l);
        List<YyProjectMilestone> milestonelis = sjProjectMilestoneService.selectSjProjectMilestoneList(sjProjectMilestone);
        for(YyProjectMilestone obj : milestonelis){
        	if(obj.getStatus()==1){
        		milestone++;
        	}
        }
        mmap.put("milestonelis", milestonelis);
        mmap.put("milestonesize", milestonelis.size());
        mmap.put("milestone", milestone);
        
        //---付款金额
        YyFk gcFk = new YyFk();
        gcFk.setDeleteFlag(1);
        gcFk.setGcProjectid(id);
        List<YyFk> fklis = gcFkService.selectGcFkList(gcFk);
        double sjfy = 0.0;//实际费用
        double sjfkfy = 0.0;//实际付款费用
        for(YyFk fk:fklis){
        	sjfy = DecimalCalculateUtil.add(sjfy, fk.getHtzje());
        	if(fk.getStatus()==2){
        		sjfkfy = DecimalCalculateUtil.add(sjfkfy, fk.getHtzje());
        	}
        }
        
        double fxje = returnJe(gcProject);
        sjfy = DecimalCalculateUtil.add(sjfy, fxje);
        sjfkfy = DecimalCalculateUtil.add(sjfkfy, fxje);
        
        mmap.put("sjfy", DecimalCalculateUtil.returnEje(sjfy));
        mmap.put("sjfkfy", DecimalCalculateUtil.returnEje(sjfkfy));
        
        //---申请开票
        YyProjectSqkp gcProjectSqkp = new YyProjectSqkp();
        gcProjectSqkp.setDeleteFlag(1);
        gcProjectSqkp.setGcProjectid(id);
        List<YyProjectSqkp> sqkplis = gcProjectSqkpService.selectGcProjectSqkpList(gcProjectSqkp);
        double pojhsrkx = gcProject.getZongje()==null?0.0:gcProject.getZongje();//项目计划收入款项
        double yjkpje = 0.0;//预计开票金额
        double ykfpje = 0.0;//已开发票金额
        double ljdkje = 0.0;//累计到款金额
        double ysje = 0.0;//应收金额
        for(YyProjectSqkp sqkp:sqkplis){
        	yjkpje = DecimalCalculateUtil.add(yjkpje, Double.parseDouble(sqkp.getItemje()));
        	if(sqkp.getStatus()==2){
        		ykfpje = DecimalCalculateUtil.add(ykfpje, Double.parseDouble(sqkp.getItemje()));
        	}
        }
        ysje = ykfpje;
        
        YyProjectQrsk gcProjectQrsk = new YyProjectQrsk(); 
        gcProjectQrsk.setDeleteFlag(1);
        gcProjectQrsk.setGcProjectid(id);
        List<YyProjectQrsk> qrsklis = gcProjectQrskService.selectGcProjectQrskList(gcProjectQrsk);
        for(YyProjectQrsk qrsk:qrsklis){
        	ljdkje = DecimalCalculateUtil.add(ljdkje, qrsk.getQrjine());
        }
        
        mmap.put("pojhsrkx", DecimalCalculateUtil.returnEje(pojhsrkx));
        mmap.put("yjkpje", DecimalCalculateUtil.returnEje(yjkpje));
        mmap.put("ykfpje", DecimalCalculateUtil.returnEje(ykfpje));
        mmap.put("ljdkje", DecimalCalculateUtil.returnEje(ljdkje));
        mmap.put("ysje", DecimalCalculateUtil.returnEje(ysje));
        
        //判断是成员，还是管理员
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
    	//----判断看个人或领导
        int flag = 0;//成员
    	if(getSysUser().isShowRoleIds(roleIds)){
    		//角色不是董事、总经理、管理员
    		SjProjectPeople sjProjectPeople = new SjProjectPeople();
            sjProjectPeople.setDeleteFlag(1);
            sjProjectPeople.setGcProjectid(id);
            sjProjectPeople.setCode(getUserId().toString());
            List<SjProjectPeople> peoplelis = sjProjectPeopleService.selectSjProjectPeopleList(sjProjectPeople);
            if(peoplelis!=null && peoplelis.size()>0){
            	for(SjProjectPeople po:peoplelis){
                	if(po.getpId()==0l){
                		flag = 1;//领导
                		break;
                	}
                }
            }
        }else{
        	flag = 1;//领导
        }
        
        mmap.put("flag", flag);
        return "yy/project/projectDetail";
    }
    
    private Double returnJe(YyProject gcProject){
    	double je = 0.0;//财务分项金额
    	GcBszbzfd gcBszbzfd = new GcBszbzfd();
    	gcBszbzfd.setDeleteFlag(1);
    	gcBszbzfd.setGcProjectid(gcProject.getId());
    	List<GcBszbzfd> gcBszbzfdlis = gcBszbzfdService.selectGcBszbzfdList(gcBszbzfd);
    	for(GcBszbzfd bzj:gcBszbzfdlis){
    		je=DecimalCalculateUtil.add(je, Double.parseDouble(bzj.getHejexx()));
    	}
    	
    	GcClbxd gcClbxd = new GcClbxd();
    	gcClbxd.setDeleteFlag(1);
    	gcClbxd.setGcProjectid(gcProject.getId());
    	List<GcClbxd> clbxlis = gcClbxdService.selectGcClbxdList(gcClbxd);
    	for(GcClbxd obj:clbxlis){
    		je=DecimalCalculateUtil.add(je, Double.parseDouble(obj.getHejexx()));
    	}
    	
    	GcFyhx gcFyhx = new GcFyhx();
    	gcFyhx.setDeleteFlag(1);
    	gcFyhx.setGcProjectid(gcProject.getId());
    	List<GcFyhx> fyhxlis = gcFyhxService.selectGcFyhxList(gcFyhx);
    	for(GcFyhx obj:fyhxlis){
    		je=DecimalCalculateUtil.add(je, Double.parseDouble(obj.getHejexx()));
    	}
    	
		return je;
    }

    @GetMapping()
    public String project(ModelMap mmap){
    	//所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/project";
    }

    /**
     * 查询项目立项列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YyProject gcProject)
    {
        //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        
        startPage();
        gcProject.setDeleteFlag(1);
        if(count != 0){
        	//看部门
        	gcProject.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		//不是董事或总经理，则判断是不是项目选择的主创、成本经理等人员
        		gcProject.setOwnerId(getUserId());
            	gcProject.setCyId(getUserId());
            }
        }
        
        //----
        List<YyProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(YyProject obj : list){
        	if(obj.getAuthority()==null || obj.getAuthority().toString().equals("")){
        		obj.setAuthorityName("");
        	}else{
        		SysDept dept = deptService.selectDeptById(Long.parseLong(obj.getAuthority().toString()));
            	obj.setAuthorityName(dept.getDeptName());
        	}
        }
        
        return getDataTable(list);
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listAll")
    @ResponseBody
    public TableDataInfo listAll(YyProject gcProject)
    {
        //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        
        startPage();
        gcProject.setDeleteFlag(1);
        gcProject.setStatus(3);
        
        if(count != 0){
        	//看部门
        	gcProject.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		gcProject.setOwnerId(getUserId());
            	gcProject.setCyId(getUserId());
            }
        }
        //----
        List<YyProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(YyProject obj : list){
        	if(obj.getAuthority()==null || obj.getAuthority().toString().equals("")){
        		obj.setAuthorityName("");
        	}else{
        		SysDept dept = deptService.selectDeptById(Long.parseLong(obj.getAuthority().toString()));
            	obj.setAuthorityName(dept.getDeptName());
        	}
        }
        
        return getDataTable(list);
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listJx")
    @ResponseBody
    public TableDataInfo listJx(YyProject gcProject)
    {
        //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        
        startPage();
        gcProject.setStatus(3);
        gcProject.setDeleteFlag(1);
        
        if(count != 0){
        	//看部门
        	gcProject.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		gcProject.setOwnerId(getUserId());
            	gcProject.setCyId(getUserId());
            }
        }
        //----
        List<YyProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(YyProject obj : list){
        	if(obj.getAuthority()==null || obj.getAuthority().toString().equals("")){
        		obj.setAuthorityName("");
        	}else{
        		SysDept dept = deptService.selectDeptById(Long.parseLong(obj.getAuthority().toString()));
            	obj.setAuthorityName(dept.getDeptName());
        	}
        }
        
        return getDataTable(list);
    }
    
    /**
     * 查询项目立项列表
     */
    @PostMapping("/listJs")
    @ResponseBody
    public TableDataInfo listJs(YyProject gcProject)
    {
        //角色数据权限 ==根据用户定义的数据权限查看项目数据
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
        int count = roleService.selectCountRoleDeptByRoleId(roleIds);
        
        startPage();
        gcProject.setDeleteFlag(1);
        gcProject.setStatus(7);//竣工
        
        if(count != 0){
        	//看部门
        	gcProject.setRoleIds(roleIds);
        }else{
        	//看个人
        	if(getSysUser().isShowRoleIds(roleIds)){
        		gcProject.setOwnerId(getUserId());
            	gcProject.setCyId(getUserId());
            }
        }
        //----
        
        List<YyProject> list = gcProjectService.selectGcProjectList(gcProject);
        for(YyProject obj : list){
        	if(obj.getAuthority()==null || obj.getAuthority().toString().equals("")){
        		obj.setAuthorityName("");
        	}else{
        		SysDept dept = deptService.selectDeptById(Long.parseLong(obj.getAuthority().toString()));
            	obj.setAuthorityName(dept.getDeptName());
        	}
        }
        
        return getDataTable(list);
    }

    /**
     * 导出项目立项列表
     */
    @Log(title = "项目立项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YyProject gcProject)
    {
    	gcProject.setDeleteFlag(1);
        List<YyProject> list = gcProjectService.selectGcProjectList(gcProject);
        ExcelUtil<YyProject> util = new ExcelUtil<YyProject>(YyProject.class);
        return util.exportExcel(list, "项目立项数据");
    }

    /**
     * 新增项目立项
     */
    @GetMapping("/add")
    public String add(ModelMap mmap){
    	
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	mmap.put("owner", getLoginName());
    	mmap.put("ownerId", getUserId());
    	mmap.put("deptName", getSysUser().getDept().getDeptName());
    	mmap.put("deptId", getSysUser().getDept().getDeptId());
    	
    	YyBidding sjBidding = new YyBidding();
    	sjBidding.setDeleteFlag(1);
    	sjBidding.setOwner(getLoginName());
    	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
    	mmap.put("biddinglis", biddinglis);
    	
    	//下一级审核人
        List<SjProcessConfig> configlis = returnUser(getSysUser().getDept().getDeptId());
        mmap.put("approveid", configlis.get(0).getLevel1id());
        mmap.put("approvename", configlis.get(0).getLevel1name());
        
        //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/add";
    }

    /**
     * 新增保存项目立项
     */
    @Log(title = "项目立项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YyProject gcProject){
    	
//    	SimpleDateFormat sdy = new SimpleDateFormat("yyyy");
//		SimpleDateFormat sdm = new SimpleDateFormat("MM");
//		int year = Integer.parseInt(sdy.format(new Date()));
//		int month = Integer.parseInt(sdm.format(new Date()));
//		YyProject newObj = new YyProject();
//		newObj.setDeleteFlag(1);
//		newObj.setCreateAt(DateUtils.getFisrtDayOfMonth(year, 1));
//		newObj.setUpdateAt(DateUtils.getLastDayOfMonth(year, 12));
//		List<YyProject> lisCount = gcProjectService.selectGcProjectList(newObj);
		
		//项目跟踪
//		SjBidding sjBidding = sjBiddingService.selectSjBiddingById(gcProject.getBiddingId());
//		if(sjBidding!=null){
//			gcProject.setBidding(sjBidding.getProjectName());
//			gcProject.setBiddingId(sjBidding.getId());
//			gcProject.setCustomerName(sjBidding.getCustomerName());
//			gcProject.setGroupName(sjBidding.getId().toString());
//		}
		
		GcCustomer gcCustomer = gcCustomerService.selectGcCustomerById(gcProject.getCustomerId());
		gcProject.setCustomerName(gcCustomer.getName());
		
//    	gcProject.setOrderNo(ReturnUUID.getOrderNo("HT"));
//		String no = String.format("%02d", lisCount.size()+1);
//		gcProject.setOrderNo(year+"-"+no);
		gcProject.setNsctje(returnNsctje(gcProject));
//		gcProject.setJsNo(year+"-"+month);
//		gcProject.setYearStr(year+"");
    	gcProject.setStatus(3);//状态1
    	gcProject.setOwner(getLoginName());
    	gcProject.setDeleteFlag(1);
    	gcProject.setCreateAt(new Date());
    	gcProject.setUpdateAt(new Date());
    	gcProject.setCreateUser(getLoginName());
    	gcProject.setUpdateUser(getLoginName());
    	gcProjectService.insertGcProject(gcProject);
    	
    	addPlan(gcProject);
    	
    	try {
    		//发送消息通知
        	gcSendTipService.sendTipXm("xmht", gcProject.getName(), gcProject.getOrderNo(), 
        			gcProject.getCreateUser(), DateUtils.dateTime(gcProject.getCreateAt()), 
        			gcProject.getStatus().toString(), null, gcProject.getId().toString());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
    	
        return toAjax(1);
    }
    
    
    //添加项目成员
    private void addProjectPeople(YyProject gcProject){
    	sjProjectPeopleService.deleteSjProjectPeople4Gid(gcProject.getId());
    	
    	//项目董事
    	SjProjectPeople sjProjectPeople = new SjProjectPeople();
    	sjProjectPeople.setDeleteFlag(1);
    	sjProjectPeople.setGcProjectid(gcProject.getId());
    	sjProjectPeople.setpId(0l);
    	sjProjectPeople.setName(gcProject.getProDsz());
    	sjProjectPeople.setCode(gcProject.getProDszId().toString());
    	sjProjectPeople.setRuleName("2");
    	sjProjectPeople.setQz("100");
    	sjProjectPeopleService.insertSjProjectPeople(sjProjectPeople);
    	
    	//商务经理
    	SjProjectPeople sjProjectPeople1 = new SjProjectPeople();
    	sjProjectPeople1.setDeleteFlag(1);
    	sjProjectPeople1.setGcProjectid(gcProject.getId());
    	sjProjectPeople1.setpId(0l);
    	sjProjectPeople1.setName(gcProject.getProSwjl());
    	sjProjectPeople1.setCode(gcProject.getProSwjlId().toString());
    	sjProjectPeople1.setRuleName("3");
    	sjProjectPeople1.setQz("100");
    	sjProjectPeopleService.insertSjProjectPeople(sjProjectPeople1);
    	
    	//项目方案主创
    	SjProjectPeople sjProjectPeople2 = new SjProjectPeople();
    	sjProjectPeople2.setDeleteFlag(1);
    	sjProjectPeople2.setGcProjectid(gcProject.getId());
    	sjProjectPeople2.setpId(0l);
    	sjProjectPeople2.setName(gcProject.getProFazc());
    	sjProjectPeople2.setCode(gcProject.getProFazcId().toString());
    	sjProjectPeople2.setRuleName("1");
    	sjProjectPeople2.setQz("100");
    	sjProjectPeopleService.insertSjProjectPeople(sjProjectPeople2);
    	
    	//项目方案主创
    	SjProjectPeople sjProjectPeople3 = new SjProjectPeople();
    	sjProjectPeople3.setDeleteFlag(1);
    	sjProjectPeople3.setpId(0l);
    	sjProjectPeople3.setGcProjectid(gcProject.getId());
    	sjProjectPeople3.setName(gcProject.getProFzr());
    	sjProjectPeople3.setCode(gcProject.getProFzrId().toString());
    	sjProjectPeople3.setRuleName("4");
    	sjProjectPeople3.setQz("100");
    	sjProjectPeopleService.insertSjProjectPeople(sjProjectPeople3);
    }
    
    //添加成果文件
    private void addResult(YyProject gcProject){
    	SysDictData dictData = new SysDictData();
    	dictData.setDictType("sj_resultType");
    	List<SysDictData> dictdatalis = sysDictDataService.selectDictDataList(dictData);
    	
    	for(SysDictData obj:dictdatalis){
    		YyProjectReust sjProjectReust = new YyProjectReust();
    		sjProjectReust.setGcProjectid(gcProject.getId());
    		sjProjectReust.setProjectName(gcProject.getName());
        	sjProjectReust.setOrderNo(ReturnUUID.getOrderNo("CG"));
        	sjProjectReust.setType(obj.getDictValue());
        	sjProjectReust.setDeleteFlag(1);
        	sjProjectReust.setCreateUser(getLoginName());
        	sjProjectReust.setCreateAt(new Date());
        	sjProjectReust.setUpdateUser(getLoginName());
        	sjProjectReust.setUpdateAt(new Date());
        	sjProjectReustService.insertSjProjectReust(sjProjectReust);
    	}
    }
    
    //添加售前计划
    private void addPlan(YyProject gcProject){
    	YyProjectMilestone sjProjectMilestone = new YyProjectMilestone();
    	sjProjectMilestone.setpId(0l);
    	sjProjectMilestone.setGcProjectid(gcProject.getId());
    	sjProjectMilestone.setOrderNo("A001");
    	sjProjectMilestone.setName("售前阶段");
    	sjProjectMilestone.setStatus(0);
    	sjProjectMilestone.setPstartAt(new Date());
    	sjProjectMilestone.setPendAt(new Date());
    	sjProjectMilestone.setSstartAt(new Date());
    	sjProjectMilestone.setSendAt(new Date());
    	sjProjectMilestone.setCount(new BigDecimal(1));
    	sjProjectMilestone.setJdbfb("0");
    	sjProjectMilestone.setSort(0);
    	sjProjectMilestone.setOwner(gcProject.getOwner());
    	sjProjectMilestone.setOwnerId(gcProject.getOwnerId());
    	sjProjectMilestone.setDeleteFlag(1);
    	sjProjectMilestone.setCreateUser(getLoginName());
    	sjProjectMilestone.setCreateAt(new Date());
    	sjProjectMilestone.setUpdateUser(getLoginName());
    	sjProjectMilestone.setUpdateAt(new Date());
    	sjProjectMilestoneService.insertSjProjectMilestone(sjProjectMilestone);
    }
    
    private Double returnNsctje(YyProject gcProject){
    	double nsctje = 0.0;
    	try {
    		if(gcProject.getNsctType()==1){//合同额*2% 
        		nsctje = gcProject.getZongje()*0.02;
        	}else if(gcProject.getNsctType()==2){//0.4/平方米 
        		nsctje = gcProject.getMianji()*0.4;
        	}else if(gcProject.getNsctType()==0){//0.4/平方米 
        		nsctje = 0.0;
        	}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			nsctje = 0.0;
		}
    	
		return nsctje;
    }
    
    /**
     * 修改项目立项
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
    	YyProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	YyBidding sjBidding = new YyBidding();
    	sjBidding.setDeleteFlag(1);
    	sjBidding.setOwner(getLoginName());
    	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
    	mmap.put("biddinglis", biddinglis);
    	
    	//下一级审核人
        List<SjProcessConfig> configlis = returnUser(getSysUser().getDept().getDeptId());
        mmap.put("approveid", configlis.get(0).getLevel1id());
        mmap.put("approvename", configlis.get(0).getLevel1name());
        
        //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/edit";
    }
    
    /**
     * 修改项目立项
     */
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
    	YyProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	YyBidding sjBidding = new YyBidding();
    	sjBidding.setDeleteFlag(1);
    	sjBidding.setOwner(getLoginName());
    	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
    	mmap.put("biddinglis", biddinglis);
    	
    	//下一级审核人
        List<SjProcessConfig> configlis = returnUser(getSysUser().getDept().getDeptId());
        mmap.put("approveid", configlis.get(0).getLevel1id());
        mmap.put("approvename", configlis.get(0).getLevel1name());
        
        //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/detail";
    }
    
    /**
     * 修改保存项目立项
     */
    @Log(title = "项目立项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YyProject gcProject){
    	
    	//项目跟踪
//    	SjBidding sjBidding = sjBiddingService.selectSjBiddingById(gcProject.getBiddingId());
//		if(sjBidding!=null){
//			gcProject.setBidding(sjBidding.getProjectName());
//			gcProject.setBiddingId(sjBidding.getId());
//			gcProject.setCustomerName(sjBidding.getCustomerName());
//			gcProject.setGroupName(sjBidding.getId().toString());
//		}
    	
    	GcCustomer gcCustomer = gcCustomerService.selectGcCustomerById(gcProject.getCustomerId());
		gcProject.setCustomerName(gcCustomer.getName());
    	
		gcProject.setNsctje(returnNsctje(gcProject));
    	gcProjectService.updateGcProject(gcProject);
    	
        return toAjax(1);
    }
    
    @GetMapping("/project4All")
    public String project4All(ModelMap mmap){
    	//所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return "yy/project/project4All";
    }
    
    @GetMapping("/project4Jx")
    public String project4Jx(ModelMap mmap){
    	//所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return "yy/project/project4Jx";
    }
    
    @GetMapping("/project4Js")
    public String project4Js(ModelMap mmap){
    	//所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return "yy/project/project4Js";
    }
    
    @PostMapping("/proClose")//项目关闭
    @ResponseBody
    public AjaxResult proClose(YyProject gcProject){
    	gcProject.setStatus(7);
    	gcProject.setUpdateUser(getLoginName());
    	gcProject.setUpdateAt(new Date());
    	gcProjectService.updateGcProject(gcProject);
        return toAjax(1);
    }
    
    /**
     * 删除差旅核销单
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids){
        return toAjax(gcProjectService.deleteGcProjectByIds(ids));
    }
    
    //---------------------审批方法
    //申请人部门PID
    private List<SjProcessConfig> returnUser(Long deptId){
    	SysDept dept = deptService.selectDeptById(deptId);
    	SjProcessConfig sjProcessConfig = new SjProcessConfig();
        sjProcessConfig.setDeleteFlag(1);
        sjProcessConfig.setCode(processCode);
        sjProcessConfig.setDeptId(dept.getParentId());
        List<SjProcessConfig> configlis = sjProcessConfigService.selectSjProcessConfigList(sjProcessConfig);
		
        if(configlis==null || configlis.size()==0){
        	SjProcessConfig sjProcessConfig1 = new SjProcessConfig();
        	sjProcessConfig1.setDeleteFlag(1);
        	sjProcessConfig1.setCode("morenliucheng");
            List<SjProcessConfig> configlis1 = sjProcessConfigService.selectSjProcessConfigList(sjProcessConfig1);
            return configlis1;
        }
        return configlis;
    }
    
    /**
     * 修改保存项目立项
     */
    @Log(title = "项目立项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit4check")
    @ResponseBody
    public AjaxResult edit4check(YyProject gcProject){
		gcProject.setNsctje(returnNsctje(gcProject));
		gcProject.setUpdateAt(new Date());
		gcProject.setUpdateUser(getLoginName());
        return toAjax(gcProjectService.updateGcProject4check(gcProject));
    }
    
    /**
     * level1
     * @return
     */
    @GetMapping("/level1")
    public String level1(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	YyProject obj = gcProjectService.selectGcProjectById(Long.parseLong(p.getBusinessKey().toString()));
        	mmap.put("obj", obj);
        	
        	YyBidding sjBidding = new YyBidding();
        	sjBidding.setDeleteFlag(1);
        	sjBidding.setOwner(getLoginName());
        	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
        	mmap.put("biddinglis", biddinglis);
        	
        	GcCustomer gcCustomer = new GcCustomer();
        	gcCustomer.setDeleteFlag(1);
        	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
        	mmap.put("clis", gcCustomerlis);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
            
            //下一级审核人
            mmap.put("approveid", obj.getBmsprId());//部门审核人
            mmap.put("approvename", obj.getBmspr());
        }
        
        return prefix + "/level1check";
    }
    
    /**
     * level2
     * @return
     */
    @GetMapping("/level2")
    public String level2(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	YyProject obj = gcProjectService.selectGcProjectById(Long.parseLong(p.getBusinessKey().toString()));
        	mmap.put("obj", obj);
        	
        	YyBidding sjBidding = new YyBidding();
        	sjBidding.setDeleteFlag(1);
        	sjBidding.setOwner(getLoginName());
        	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
        	mmap.put("biddinglis", biddinglis);
        	
        	GcCustomer gcCustomer = new GcCustomer();
        	gcCustomer.setDeleteFlag(1);
        	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
        	mmap.put("clis", gcCustomerlis);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
            
            //下一级审核人
            List<SjProcessConfig> configlis = returnUser(Long.valueOf(obj.getDeptId().toString()));
            mmap.put("approveid", configlis.get(0).getLevel3id());
            mmap.put("approvename", configlis.get(0).getLevel3name());
        }
        
        return prefix + "/level2check";
    }
    
    /**
     * level3
     * @return
     */
    @GetMapping("/level3")
    public String level3(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	YyProject obj = gcProjectService.selectGcProjectById(Long.parseLong(p.getBusinessKey().toString()));
        	mmap.put("obj", obj);
        	
        	YyBidding sjBidding = new YyBidding();
        	sjBidding.setDeleteFlag(1);
        	sjBidding.setOwner(getLoginName());
        	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
        	mmap.put("biddinglis", biddinglis);
        	
        	GcCustomer gcCustomer = new GcCustomer();
        	gcCustomer.setDeleteFlag(1);
        	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
        	mmap.put("clis", gcCustomerlis);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
            
          //所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
            
            //下一级审核人
            List<SjProcessConfig> configlis = returnUser(Long.valueOf(obj.getDeptId().toString()));
            mmap.put("approveid", configlis.get(0).getLevel4id());
            mmap.put("approvename", configlis.get(0).getLevel4name());
        }
        
        return prefix + "/level3check";
    }
    
    /**
     * level4
     * @return
     */
    @GetMapping("/level4")
    public String level4(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	YyProject obj = gcProjectService.selectGcProjectById(Long.parseLong(p.getBusinessKey().toString()));
        	mmap.put("obj", obj);
        	
        	YyBidding sjBidding = new YyBidding();
        	sjBidding.setDeleteFlag(1);
        	sjBidding.setOwner(getLoginName());
        	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
        	mmap.put("biddinglis", biddinglis);
        	
        	GcCustomer gcCustomer = new GcCustomer();
        	gcCustomer.setDeleteFlag(1);
        	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
        	mmap.put("clis", gcCustomerlis);
        	
        	//所属
            SysDept dept = new SysDept();
            dept.setDelFlag("1");
            dept.setParentId(100l);
            List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
            mmap.put("deptlis", deptlis);
        	
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
        }
        
        return prefix + "/level4check";
    }
    
    /**
     * 修改单据
     * @param taskid
     * @param mmap
     * @return
     */
    @GetMapping("/modify")
    public String modify(String taskid, ModelMap mmap){
        Task t = taskService.createTaskQuery().taskId(taskid).singleResult();
        String processId = t.getProcessInstanceId();
        ProcessInstance p = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        if (p != null) {
        	YyProject gcProject = gcProjectService.selectGcProjectById(Long.parseLong(p.getBusinessKey().toString()));
            mmap.put("obj", gcProject);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            mmap.put("taskid", taskid);
        }
        
        YyBidding sjBidding = new YyBidding();
    	sjBidding.setDeleteFlag(1);
    	sjBidding.setOwner(getLoginName());
    	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
    	mmap.put("biddinglis", biddinglis);
    	
    	GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	//所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        
        return prefix + "/modifycheck";
    }
    
    @GetMapping("/project4ZcAll/{id}")
    public String project4ZcAll(ModelMap mmap,@PathVariable("id") Long id){
    	YyProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        
        //-----------------总支出
        double zzc = 0.0;
        List<Double> mouthDates = new ArrayList<Double>();
        List<Map> list = gcProjectService.selectZc4po(gcProject.getId());
        Map repMonth = new HashedMap();
        for(Map rep:list){
        	if(!rep.get("status").toString().equals("3")){
        		continue;
        	}
        	
        	zzc += Double.valueOf(rep.get("hejexx").toString());
        	
        	//-----------------月支出趋势 ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
        	String createAt = rep.get("createAt").toString();
        	int month = DateUtils.getDaysByMonth(createAt);
        	if(repMonth.get(month)==null){
        		repMonth.put(month, Double.valueOf(rep.get("hejexx").toString()));
        	}else{
        		double zc4month = Double.valueOf(repMonth.get(month).toString())+Double.valueOf(rep.get("hejexx").toString());
        		repMonth.put(month, zc4month);
        	}
        }
        
        mmap.put("zzc", zzc);//总支出
        
        for(int i=0;i<12;i++){
        	if(repMonth.get(i)==null){
        		mouthDates.add(0.0);
        	}else{
        		mouthDates.add(Double.valueOf(repMonth.get(i).toString()));
        	}
        }
        mmap.put("mouthDates", mouthDates.toArray());//月支出趋势
        
        //----------------------------占总支出占比
        //0税金及管理费  1业务费 2项目绩效 3商务费用 4图文制作支出 5其他 6投标费用 7差旅报销
        //['直接访问','邮件营销','联盟广告','视频广告','搜索引擎']
        //{value:335, name:'直接访问'},{value:310, name:'邮件营销'}
        String[] zczbArr = {"税金及管理费","业务费","项目绩效","商务费用","图文制作支出","其他","投标费用","差旅报销"};
        List<Map> zczbLis = new ArrayList<Map>();
        for(int i=0;i<zczbArr.length;i++){
        	Map repMap = new HashedMap();
            repMap.put("name", zczbArr[i]);
            repMap.put("value", returnZc(i, id, zczbArr[i]));
            zczbLis.add(repMap);
        }
        mmap.put("zczbArr", zczbArr);
        mmap.put("zczbLis", zczbLis);
        
        //----------------------------占收入出占比
        double srzb = 0.0;
        YyProjectQrsk gcProjectQrsk = new YyProjectQrsk();
        gcProjectQrsk.setDeleteFlag(1);
        gcProjectQrsk.setGcProjectid(id);
        List<YyProjectQrsk> qrsklis = gcProjectQrskService.selectGcProjectQrskList(gcProjectQrsk);
        for(YyProjectQrsk qrsk:qrsklis){
        	srzb = DecimalCalculateUtil.add(srzb, qrsk.getQrjine());
        }
        
        String[] srzbArr = {"税金及管理费","业务费","项目绩效","商务费用","图文制作支出","其他","投标费用","差旅报销","收入"};
        List<Map> srzbLis = new ArrayList<Map>();
        for(int i=0;i<srzbArr.length;i++){
        	
        	srzb = DecimalCalculateUtil.sub(srzb, returnZc(i, id, srzbArr[i]));
        	
        	Map repMap = new HashedMap();
        	if(i == srzbArr.length-1){
        		repMap.put("name", srzbArr[i]);
                repMap.put("value", srzb<0?0.0:srzb);
                srzbLis.add(repMap);
        	}else{
        		repMap.put("name", srzbArr[i]);
                repMap.put("value", returnZc(i, id, srzbArr[i]));
                srzbLis.add(repMap);
        	}
        }
        mmap.put("srzbArr", srzbArr);
        mmap.put("srzbLis", srzbLis);
        
        //判断是成员，还是管理员
        List<SysRole> roles = getSysUser().getRoles();
        List<Long> roleIds = new ArrayList<Long>();
        for(SysRole obj:roles){
        	roleIds.add(obj.getRoleId());
        }
        
    	//看个人
        int flag = 0;//成员
    	if(getSysUser().isShowRoleIds(roleIds)){
    		SjProjectPeople sjProjectPeople = new SjProjectPeople();
            sjProjectPeople.setDeleteFlag(1);
            sjProjectPeople.setGcProjectid(id);
            sjProjectPeople.setCode(getUserId().toString());
            List<SjProjectPeople> peoplelis = sjProjectPeopleService.selectSjProjectPeopleList(sjProjectPeople);
            if(peoplelis!=null && peoplelis.size()>0){
            	for(SjProjectPeople po:peoplelis){
                	if(po.getpId()==0l){
                		flag = 1;//领导
                		break;
                	}
                }
            }
        }else{
        	flag = 1;//领导
        }
        
        mmap.put("flag", flag);
        return "yy/project/projectDetailZcAll";
    }
    
    private double returnZc(int x,Long gcProjectid,String type){
    	double zongjine = 0.0;
    	//0税金及管理费  1业务费 2项目绩效 3商务费用 4图文制作支出 5其他 6投标费用 7差旅报销
    	if(x==6){
    		zongjine = returnBszbzfd(gcProjectid);
    	}else if(x==7){
    		zongjine = returnClbxd(gcProjectid);
    	}else{
    		zongjine = returnFyhx(gcProjectid, type);
    	}
		return zongjine;
    }
    
    /**
     * 费用核销	0税金及管理费  1业务费 2项目绩效 3商务费用 4图文制作支出 5其他
     * @param gcProjectid
     * @param type
     * @return
     */
    private double returnFyhx(Long gcProjectid,String type){
    	double zongjine = 0.0;
    	GcFyhx gcFyhx = new GcFyhx();
        gcFyhx.setDeleteFlag(1);
        gcFyhx.setType(type);
        gcFyhx.setGcProjectid(gcProjectid);
        gcFyhx.setStatus(3);
        List<GcFyhx> fyhxlis = gcFyhxService.selectGcFyhxList(gcFyhx);
        for(GcFyhx fyhx:fyhxlis){
//        	zongjine += Double.valueOf(fyhx.getHejexx());
        	zongjine = DecimalCalculateUtil.add(zongjine, Double.parseDouble(fyhx.getHejexx()));
        }
		return zongjine;
    }
    
    /**
     * 6投标费用
     * @param gcProjectid
     * @return
     */
    private double returnBszbzfd(Long gcProjectid){
    	double zongjine = 0.0;
    	GcBszbzfd gcBszbzfd = new GcBszbzfd();
    	gcBszbzfd.setDeleteFlag(1);
    	gcBszbzfd.setGcProjectid(gcProjectid);
    	gcBszbzfd.setStatus(3);
    	List<GcBszbzfd> gcBszbzfdlis = gcBszbzfdService.selectGcBszbzfdList(gcBszbzfd);
    	for(GcBszbzfd bzj:gcBszbzfdlis){
    		zongjine=DecimalCalculateUtil.add(zongjine, Double.parseDouble(bzj.getHejexx()));
    	}
    	return zongjine;
    }
    
    /**
     * 7差旅报销
     * @param gcProjectid
     * @return
     */
    private double returnClbxd(Long gcProjectid){
    	double zongjine = 0.0;
    	GcClbxd gcClbxd = new GcClbxd();
    	gcClbxd.setDeleteFlag(1);
    	gcClbxd.setGcProjectid(gcProjectid);
    	gcClbxd.setStatus(3);
    	List<GcClbxd> clbxlis = gcClbxdService.selectGcClbxdList(gcClbxd);
    	for(GcClbxd obj:clbxlis){
    		zongjine=DecimalCalculateUtil.add(zongjine, Double.parseDouble(obj.getHejexx()));
    	}
    	return zongjine;
    }
	
    /**
     * 查询项目立项列表
     */
    @PostMapping("/list4ZcAll")
    @ResponseBody
    public TableDataInfo list4ZcAll(GcProject gcProject){
        List<Map> list = gcProjectService.selectZc4po(gcProject.getId());
        return getDataTable(list);
    }
    
    /**
     * 修改项目立项
     */
    @RequiresPermissions("system:yyproject:againedit")
    @GetMapping("/againedit/{id}")
    public String againedit(@PathVariable("id") Long id, ModelMap mmap)
    {
    	YyProject gcProject = gcProjectService.selectGcProjectById(id);
        mmap.put("gcProject", gcProject);
        GcCustomer gcCustomer = new GcCustomer();
    	gcCustomer.setDeleteFlag(1);
    	List<GcCustomer> gcCustomerlis = gcCustomerService.selectGcCustomerList(gcCustomer);
    	mmap.put("clis", gcCustomerlis);
    	
    	YyBidding sjBidding = new YyBidding();
    	sjBidding.setDeleteFlag(1);
    	sjBidding.setOwner(getLoginName());
    	List<YyBidding> biddinglis = sjBiddingService.selectSjBiddingList(sjBidding);
    	mmap.put("biddinglis", biddinglis);
    	
    	//下一级审核人
        List<SjProcessConfig> configlis = returnUser(getSysUser().getDept().getDeptId());
        mmap.put("approveid", configlis.get(0).getLevel1id());
        mmap.put("approvename", configlis.get(0).getLevel1name());
        
        //所属
        SysDept dept = new SysDept();
        dept.setDelFlag("1");
        dept.setParentId(100l);
        List<SysDept> deptlis = deptService.selectDeptList4pId(dept);
        mmap.put("deptlis", deptlis);
        return prefix + "/edit";
    }
}